﻿@using Microsoft.AspNetCore.Components.Authorization
@inject NavigationManager Navigation

<AuthorizeView Context="authenticationState">
    <Authorized>
        <a href="authentication/profile">Hello, @authenticationState.User.Identity.Name!</a>
        <a href="authentication/login" @onclick="LoginWithOtherUser">Log in with another user</a>
        <button class="nav-link btn btn-link" @onclick="SignOut">Log out</button>
    </Authorized>
    <NotAuthorized>
        <a href="authentication/register">Register</a>
        <a href="authentication/login">Log in</a>
    </NotAuthorized>
</AuthorizeView>

@code {
    public void LoginWithOtherUser()
    {
        var request = new InteractiveRequestOptions { Interaction = InteractionType.SignIn, ReturnUrl = Navigation.Uri };
        request.TryAddAdditionalParameter("prompt", "login");

        Navigation.NavigateToLogin("authentication/login", request);
    }

    public void SignOut()
    {
        Navigation.NavigateToLogout("authentication/logout");
    }
}
